package gov.pbc.nn.kjgl.maintenance.handler;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.bstek.uflo.env.Context;
import com.bstek.uflo.model.ProcessInstance;
import com.bstek.uflo.process.handler.NodeEventHandler;
import com.bstek.uflo.process.node.Node;

import gov.pbc.nn.core.dao.CommonHibernateDao;
import gov.pbc.nn.kjgl.maintenance.entity.SysChange;

@Component(SysChangeOverHandler.BEAN_ID)
public class SysChangeOverHandler implements NodeEventHandler {

	public static final String BEAN_ID = "gov.pbc.nn.kjgl.maintenance.handler.SysChangeOverHandler";

	@Resource(name = CommonHibernateDao.BEAN_ID)
	private CommonHibernateDao hibernateDao;
	
	@Override
	public void enter(Node arg0, ProcessInstance pi, Context context) {
		String businessId = pi.getBusinessId();
		SysChange change = this.hibernateDao.get(businessId, SysChange.class);
		if(change.getState()!=20){
			change.setState(10);
			this.hibernateDao.update(change);
		}
	}

	@Override
	public void leave(Node arg0, ProcessInstance arg1, Context arg2) {
		// TODO Auto-generated method stub

	}

}
